<?php 

class Model_dbMove extends Model{

	function __construct(){
		db_handle('SET NAMES latin1',$param=array());
	}
	
	
	function clean_db_brand(){
		$sql = "TRUNCATE TABLE  `brand`";
		$result = db_handle($sql);		

		return true;
	}
	
	function selectOldDb_brand(){
		$param = array();
		$param['field'] = "";
		$param['where'] = "";
		$param['order'] = "id asc";
		$param['group'] = "";
		$param['limit'] = "";
		$param['pagesize'] =  $this->pagesize;
		$param['page'] = $this->page;
		$param['join'] = "";
		$param['on'] = "";
		$data = db_query_hash('brand',$param,IMOREDB);
		return $data;
	}
	
	function insertNewDB_brand($id,$name,$cname,$status,$addtime,$lastmodify){
		$insert_data = array();
		$insert_data['id'] = $id;
		$insert_data['name'] = $name;
		$insert_data['cname'] = $cname;
		$insert_data['status'] = $status;
		$insert_data['addtime'] = $addtime;
		$insert_data['lastmodify'] = $lastmodify;	
		$insert_data['addedby'] = 1;
		$insert_data['approvedby'] = 1;
		$insert_data['modifiedby'] = 1;
		
		$brand_id = db_add('brand',$insert_data);
		return $brand_id;
	}
	
	function clean_db_product_type(){
		$sql = "TRUNCATE TABLE  `product_type`";
		$result = db_handle($sql);		

		return true;
	}
	
	function selectOldDb_product_type(){
		$param = array();
		$param['field'] = "";
		$param['where'] = "";
		$param['order'] = "id asc";
		$param['group'] = "";
		$param['limit'] = "";
		$param['pagesize'] =  $this->pagesize;
		$param['page'] = $this->page;
		$param['join'] = "";
		$param['on'] = "";
		$data = db_query_hash('product_type',$param,IMOREDB);
		return $data;
	}
	
	function insertNewDB_product_type($id,$name,$cname,$status,$addtime,$lastmodify){
		$insert_data = array();
		$insert_data['id'] = $id;
		$insert_data['name'] = $name;
		$insert_data['cname'] = $cname;
		$insert_data['status'] = $status;
		$insert_data['addtime'] = $addtime;
		$insert_data['lastmodify'] = $lastmodify;	
		$insert_data['addedby'] = 1;
		$insert_data['approvedby'] = 1;
		$insert_data['modifiedby'] = 1;
		
		$product_type_id = db_add('product_type',$insert_data);
		return $product_type_id;
	}
	
	function clean_db_product_layout_category(){
		$sql = "TRUNCATE TABLE  `product_layout_category`";
		$result = db_handle($sql);		

		return true;
	}
	
	function selectOldDb_product_layout_category(){
		$param = array();
		$param['field'] = "";
		$param['where'] = "";
		$param['order'] = "id asc";
		$param['group'] = "";
		$param['limit'] = "";
		$param['pagesize'] =  $this->pagesize;
		$param['page'] = $this->page;
		$param['join'] = "";
		$param['on'] = "";
		$data = db_query_hash('product_category',$param,IMOREDB);
		return $data;
	}
	
	function insertNewDB_product_layout_category($id,$name,$cname,$status,$addtime,$lastmodify){
		$insert_data = array();
		$insert_data['id'] = $id;
		$insert_data['name'] = $name;
		$insert_data['cname'] = $cname;
		$insert_data['status'] = $status;
		$insert_data['addtime'] = $addtime;
		$insert_data['lastmodify'] = $lastmodify;	
		$insert_data['addedby'] = 1;
		$insert_data['approvedby'] = 1;
		$insert_data['modifiedby'] = 1;
		
		$product_layout_category_id = db_add('product_layout_category',$insert_data);
		return $product_layout_category_id;
	}
	
	function clean_db_product_vote_option(){
		$sql = "TRUNCATE TABLE  `product_vote_option`";
		$result = db_handle($sql);		

		return true;
	}
	
	function selectOldDb_product_vote_option(){
		$param = array();
		$param['field'] = "";
		$param['where'] = "";
		$param['order'] = "id asc";
		$param['group'] = "";
		$param['limit'] = "";
		$param['pagesize'] =  $this->pagesize;
		$param['page'] = $this->page;
		$param['join'] = "";
		$param['on'] = "";
		$data = db_query_hash('product_vote_option',$param,IMOREDB);
		return $data;
	}
	
	function insertNewDB_product_vote_option($id,$name,$cname,$status,$addtime,$lastmodify){
		$insert_data = array();
		$insert_data['id'] = $id;
		$insert_data['name'] = $name;
		$insert_data['cname'] = $cname;
		$insert_data['status'] = $status;
		$insert_data['addtime'] = $addtime;
		$insert_data['lastmodify'] = $lastmodify;
		$insert_data['addedby'] = 1;
		$insert_data['approvedby'] = 1;	
		$insert_data['modifiedby'] = 1;
		
		$product_vote_option_id = db_add('product_vote_option',$insert_data);
		return $product_vote_option_id;
	}
		
	function clean_db_product(){
		$sql = "TRUNCATE TABLE  `product`";
		$result = db_handle($sql);		

		return true;
	}
	
	function selectOldDb_product(){
		$param = array();
		$param['field'] = "";
		$param['where'] = "";
		$param['order'] = "id asc";
		$param['group'] = "";
		$param['limit'] = "";
		$param['pagesize'] =  $this->pagesize;
		$param['page'] = $this->page;
		$param['join'] = "";
		$param['on'] = "";
		$data = db_query_hash('product',$param,IMOREDB);
		return $data;
	}
	
	function insertNewDB_product($insert_data){		
		$product_id = db_add('product',$insert_data);
		return $product_id;
	}
	
	function clean_db_product_experience_reports(){
		$sql = "TRUNCATE TABLE  `product_reports`";
		$result = db_handle($sql);		

		return true;
	}
	
	function selectOldDb_product_experience_reports(){
		$param = array();
		$param['field'] = "";
		$param['where'] = "";
		$param['order'] = "id asc";
		$param['group'] = "";
		$param['limit'] = "";
		$param['pagesize'] =  $this->pagesize;
		$param['page'] = $this->page;
		$param['join'] = "";
		$param['on'] = "";
		$data = db_query_hash('product_experience_reports',$param,IMOREDB);
		return $data;
	}
	
	function insertNewDB_product_experience_reports($insert_data){		
		$product_experience_reports_id = db_add('product_reports',$insert_data);
		return $product_experience_reports_id;
	}
		
	function clean_db_product_otm_discuz_tid(){
		$sql = "TRUNCATE TABLE  `product_otm_discuz_tid`";
		$result = db_handle($sql);		

		return true;
	}
	
	function selectOldDb_product_otm_discuz_tid(){
		$param = array();
		$param['field'] = "";
		$param['where'] = "category='product'";
		$param['order'] = "id asc";
		$param['group'] = "";
		$param['limit'] = "";
		$param['pagesize'] =  $this->pagesize;
		$param['page'] = $this->page;
		$param['join'] = "";
		$param['on'] = "";
		$data = db_query_hash('commentmore',$param,IMOREDB);
		return $data;
	}
	
	function insertNewDB_product_otm_discuz_tid($insert_data){		
		$product_otm_discuz_tid_id = db_add('product_otm_discuz_tid',$insert_data);
		return $product_otm_discuz_tid_id;
	}
	
	function clean_db_product_otm_vote_option(){
		$sql = "TRUNCATE TABLE  `product_otm_vote_option`";
		$result = db_handle($sql);		

		return true;
	}
	
	function selectOldDb_product_otm_vote_option(){
		$param = array();
		$param['field'] = "";
		$param['where'] = "";
		$param['order'] = "id asc";
		$param['group'] = "";
		$param['limit'] = "";
		$param['pagesize'] =  $this->pagesize;
		$param['page'] = $this->page;
		$param['join'] = "";
		$param['on'] = "";
		$data = db_query_hash('product_otm_vote_option',$param,IMOREDB);
		return $data;
	}
	
	function insertNewDB_product_otm_vote_option($insert_data){		
		$product_otm_vote_option_id = db_add('product_otm_vote_option',$insert_data);
		return $product_otm_vote_option_id;
	}
	
	function clean_db_product_experience_reports_comment(){
		$sql = "TRUNCATE TABLE  `product_reports_comment`";
		$result = db_handle($sql);		

		return true;
	}
	
	function selectOldDb_product_experience_reports_comment(){
		$param = array();
		$param['field'] = "";
		$param['where'] = "";
		$param['order'] = "id asc";
		$param['group'] = "";
		$param['limit'] = "";
		$param['pagesize'] =  $this->pagesize;
		$param['page'] = $this->page;
		$param['join'] = "";
		$param['on'] = "";
		$data = db_query_hash('product_rp_comment',$param,IMOREDB);
		return $data;
	}
	
	function insertNewDB_product_experience_reports_comment($insert_data){		
		$product_experience_reports_comment_id = db_add('product_reports_comment',$insert_data);
		return $product_experience_reports_comment_id;
	}
	
	function product_reports_average($fieleName,$id){
		
		//$sql = "SELECT AVG($fieleName) as avg from product_reports where  $fieleName<>0 and oid=$id and status=1 and is_valid=1 and is_accept=1" ;
		$sql = "SELECT AVG($fieleName) as avg from product_reports where  $fieleName<>0 and oid=$id and status=1 and  is_accept=1" ;
		$param = array();
		$data = db_handle($sql,$param);		
		return $data['result'][0]['avg'];
	}
	
	function product_reports_count_well($well,$id){
		//$sql = "SELECT count(distinct mid) as count from product_reports where well=$well and oid=$id  and status=1 and is_valid=1 and is_accept=1";
		$sql = "SELECT count(*) as count from product_reports where well=$well and oid=$id  and status=1 and is_accept=1";
		$param = array();
		$data = db_handle($sql,$param);	
		return $data['result'][0]['count'];
	}
	
	function product_reports_groupby($fieleName,$id){
		//$sql = "SELECT $fieleName,count(distinct mid) as count from product_reports where oid=$id  and status=1 and is_valid=1 and is_accept=1 group by $fieleName";
		$sql = "SELECT $fieleName,count(*) as count from product_reports where oid=$id  and status=1 and is_accept=1 group by $fieleName";
		$param = array();
		$data = db_handle($sql,$param);	
		return $data['result'];
	}
	
	function select_product(){
		$param = array();
		$param['field'] = "";
		$param['where'] = "";
		$param['order'] = "id asc";
		$param['group'] = "";
		$param['limit'] = "";
		$param['pagesize'] =  $this->pagesize;
		$param['page'] = $this->page;
		$param['join'] = "";
		$param['on'] = "";
		$data = db_query_hash('product',$param);
		return $data;
	}
	
	function clean_db_product_reports_status(){
		$sql = "TRUNCATE TABLE  `product_reports_stat`";
		$result = db_handle($sql);		

		return true;
	}
	
	function clean_db_member_imore(){
		$sql = "TRUNCATE TABLE  `member_imore`";
		$result = db_handle($sql);		

		return true;
	}
	
	function selectOldDb_member_imore(){
		$param = array();
		$param['field'] = "";
		$param['where'] = "";
		$param['order'] = "id asc";
		$param['group'] = "";
		$param['limit'] = "";
		$param['pagesize'] =  $this->pagesize;
		$param['page'] = $this->page;
		$param['join'] = "";
		$param['on'] = "";
		$data = db_query_hash('member',$param,IMOREDB);
		return $data;
	}
	
	function insertNewDB_member_imore($insert_data){		
		$member_imore_id = db_add('member_imore',$insert_data);
		return $member_imore_id;
	}
	
	function clean_db_member_condition(){
		$sql = "TRUNCATE TABLE  `member_condition`";
		$result = db_handle($sql);		

		return true;
	}
	
	function selectOldDb_member_condition(){
		$param = array();
		$param['field'] = "";
		$param['where'] = "";
		$param['order'] = "id asc";
		$param['group'] = "";
		$param['limit'] = "";
		$param['pagesize'] =  $this->pagesize;
		$param['page'] = $this->page;
		$param['join'] = "";
		$param['on'] = "";
		$data = db_query_hash('member_experience_group',$param,IMOREDB);
		return $data;
	}
	
	function insertNewDB_member_condition($insert_data){		
		$member_condition_id = db_add('member_condition',$insert_data);
		return $member_condition_id;
	}
	
	function clean_db_condition($tablename){
		$sql = "TRUNCATE TABLE  `$tablename`";
		$result = db_handle($sql);		
		return true;
	}
	
	function selectOldDb_condition($tablename){
		$param = array();
		$param['field'] = "";
		$param['where'] = "";
		$param['order'] = "id asc";
		$param['group'] = "";
		$param['limit'] = "";
		$param['pagesize'] =  $this->pagesize;
		$param['page'] = $this->page;
		$param['join'] = "";
		$param['on'] = "";
		$data = db_query_hash($tablename,$param,IMOREDB);
		return $data;
	}
	
	function insertNewDB_condition($tablename,$insert_data){		
		$member_condition_id = db_add($tablename,$insert_data);
		return $member_condition_id;
	}
}

?>